package com.feicheng.lanniao.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.feicheng.lanniao.entity.Car;
import com.feicheng.lanniao.result.ResultInfo;
import com.feicheng.lanniao.service.ICarService;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author feichengTech
 * @since 2021-09-02
 */
@RestController
@RequestMapping("/lanniao-admin/car")
public class CarController {
	@Autowired
	private ICarService iCarService;
	@GetMapping("/all")
	public ResultInfo getAllcars() {
		return iCarService.getCarinfo();
	}
	@GetMapping("/page")
	public ResultInfo getCarlist(
			String searchKey,
			Integer conditionId, 
			Integer mileageId, 
			Integer brandId, 
			Integer sellPriceId, 
			Integer rentalPriceId,
			@RequestParam(required = false,defaultValue = "1") Integer currentPage, 
			@RequestParam(required = false,defaultValue = "10") Integer pageSize) {
		return iCarService.carList(searchKey,conditionId, mileageId, brandId, sellPriceId,rentalPriceId, currentPage, pageSize);
	}
	@DeleteMapping("/info")
	public ResultInfo deleteCar(Integer carId) {
		
		return iCarService.deleteCarById(carId);	
	}
	@PutMapping("/info")
	public ResultInfo editCar(Car car) {
	    
	    return iCarService.updateCar(car);
			
	}
	@GetMapping("/info")
	public ResultInfo selectOneCar(Integer carId) {
		
		return iCarService.selectCarById(carId);
	}
	@PostMapping("/info")
    public ResultInfo addCar(Car car) {
	
	return iCarService.addCarInfo(car);
}

}

